package myky.com.doctorapp.presenter;

import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.disposables.Disposable;
import myky.com.doctorapp.base.BaseEntity;
import myky.com.doctorapp.base.BasePresenterIm;
import myky.com.doctorapp.base.RxPageSubscribe;
import myky.com.doctorapp.base.SimpleSubscribe;
import myky.com.doctorapp.contract.MyDoctorContract;
import myky.com.doctorapp.entity.MyDoctorEntity;
import myky.com.doctorapp.entity.PageEntity;
import myky.com.doctorapp.model.MyDoctorModel;

public class MyDoctorPresenter extends BasePresenterIm<MyDoctorContract.View> implements MyDoctorContract.Presenter {

    MyDoctorModel myDoctorModel;

    public MyDoctorPresenter() {

        myDoctorModel = new MyDoctorModel();


    }

    @Override
    public void findMyDoctorList(String version, String currentPagae, String pageSize) {

        myDoctorModel.findMyDoctorList(version, currentPagae, pageSize)
                .subscribe(new RxPageSubscribe<List<MyDoctorEntity.DataBean>>() {
                    @Override
                    protected void onSuccess(List<MyDoctorEntity.DataBean> dataBeans, PageEntity pageEntity) {

                        mView.hideLoading();

                        if (dataBeans != null && dataBeans.size() > 0) {
                            mView.showPages(pageEntity);

                            mView.showDataSuccess(dataBeans);
                        }


                    }

                    @Override
                    protected void onFailed(int code, String msg) {

                        mView.logCat(msg);

                        mView.hideLoading();

                    }

                    @Override
                    public void onSubscribe(Disposable d) {

                        addSubscription(d);

                        mView.showLoadingView("请稍后");

                    }
                });
    }

    @Override
    public void allowedPermission(String casepermission, String doctorId, String version,int postion) {


        myDoctorModel.allowedPermission(casepermission, doctorId, version)
                .subscribe(new RxPageSubscribe<Object>() {
                    @Override
                    protected void onSuccess(Object o, PageEntity pageEntity) {
                        mView.hideLoading();

                        mView.showAllowedPermissionResult(postion);
                    }

                    @Override
                    protected void onFailed(int code, String msg) {
                        mView.logCat(msg);
                    }

                    @Override
                    public void onSubscribe(Disposable d) {
                        mView.showLoadingView("请稍后");

                        addSubscription(d);
                    }
                });
    }
}
